// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtWebKit 1.0
import QtQuick 1.1

Image {
    width: 1024
    height: 538
    id: background
    source: "./images/background.png"
    Image {
        x:29
        y:14
        id: peeron_logo
        source: "./images/PeerON_logo.png"
    }

    MouseArea{
        anchors.fill: parent
        onClicked: controller.clearPos()
        onMousePositionChanged: controller.moveWindows( mouseX, mouseY )
    }

    // О программе, Помощь, Настройки
    Row {
        anchors.top: parent.top
        anchors.topMargin: 6
        anchors.right: parent.right
        anchors.rightMargin: 78
        spacing: 23
        AboutHelpSet {
            id: about
            textmenu: "о программе"
        }

        AboutHelpSet {
            id: help
            textmenu: "помощь"
        }

        AboutHelpSet {
            id: settings
            textmenu: "настройки"
            action: veiwModel.settings
        }
    }

    SystemButton {
        id: exit_box
        anchors.rightMargin: 8
        action: veiwModel.exit
    }
    SystemButton {
        id: minimaze_box
        anchors.rightMargin: 35
        action: veiwModel.minimize
    }
    // Строка поиска + кнопка
    Row {
        id: find_box
        anchors.top: parent.top
        anchors.topMargin: 32
        anchors.right: parent.right
        anchors.rightMargin: 40
        Rectangle {
            width: 224
            height: 25
            color: "white"
            radius: 5
            border.color: "#999999"
            TextInput {
                id: text_find
                text: qsTr("Найти...")
                font.family: "Tahoma"
                anchors.rightMargin: 5
                anchors.bottomMargin: 2
                anchors.leftMargin: 7
                anchors.topMargin: 6
                anchors.fill: parent
                horizontalAlignment: TextInput.AlignLeft
            }
        }

        Image {
            id: find_button
            source: "./images/find.png"
        }
    }
    // Главное меню
    Image {
        id: backgroud4buttons
        anchors.horizontalCenterOffset: -64
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.top: parent.top
        anchors.topMargin: 11
        source: "./images/background4buttons.png"

        Row{
            anchors.horizontalCenter: parent.horizontalCenter
            anchors.verticalCenter: parent.verticalCenter
            spacing: 3


            MainMenuButton{
                id: media
                action: veiwModel.mediaPage
            }
            MainMenuButton{
                id: search
                action: veiwModel.searchPage
            }
            MainMenuButton{
                id: uploads
                action: veiwModel.uploadsPage
            }
            MainMenuButton{
                id: chat
                action: veiwModel.chatPage
            }
            MainMenuButton{
                id: hubs
                action: veiwModel.hubsPage
            }


        }

    }

    Rectangle{
        id: web_view_radius
        radius: 5
        anchors.rightMargin: 65
        anchors.leftMargin: 59
        anchors.topMargin: 80
        anchors.bottomMargin: 52
        anchors.fill: parent
        border.color: "#999999"
        WebView {
            id: web_view
            anchors.rightMargin: 1
            anchors.leftMargin: 1
            anchors.topMargin: 3
            anchors.bottomMargin: 2
            anchors.fill: parent
            visible: false
            url: "http://dcp.peeron.ru/"
        }
        Rectangle {
            id: search_view
            anchors.rightMargin: 1
            anchors.leftMargin: 1
            anchors.topMargin: 3
            anchors.bottomMargin: 2
            anchors.fill: parent
            visible: false
        }
        ListView {
            id: uploads_view
            anchors.rightMargin: 1
            anchors.leftMargin: 1
            anchors.topMargin: 3
            anchors.bottomMargin: 2
            anchors.fill: parent
            visible: false
        }
        Rectangle {
            id: chat_view
            anchors.rightMargin: 1
            anchors.leftMargin: 1
            anchors.topMargin: 3
            anchors.bottomMargin: 2
            anchors.fill: parent
            visible: false
            ListView {
                id: chatmsglist
                anchors.fill: parent
                model: veiwModel.mainHub.chat
                delegate: Text{
                    anchors.right: parent.right
                    anchors.left: parent.left
                    wrapMode: Text.WordWrap
                    text: modelData
                }
            }
        }
        Rectangle {
            id: hubs_view
            anchors.rightMargin: 1
            anchors.leftMargin: 1
            anchors.topMargin: 3
            anchors.bottomMargin: 2
            anchors.fill: parent
            visible: false

            ListView {
                anchors.centerIn: parent.Center
                model: veiwModel.hubs
                delegate: Rectangle{
                    Text{
                        id: hubNameText
                        anchors.top: parent.top
                        anchors.centerIn: parent.Center
                        font.family: "Arial"
                        font.pixelSize: 32
                        text: modelData.hubName
                    }
                    Text {
                        id: hubAddressText
                        anchors.top: hubNameText.bottom
                        anchors.right: hubNameText.right
                        font.family: "Arial"
                        font.pixelSize: 14
                        text: modelData.address
                    }
                    Text {
                        anchors.top: hubAddressText.bottom
                        font.family: "Arial"
                        font.pixelSize: 14
                        text: modelData.currentDescription
                    }
                }
            }
        }
    }
    Image {
        id: foot
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 0
        source: "./images/foot.png"
    }

    state: veiwModel.pageName;

    states: [
        State {
            name: "media"
            PropertyChanges { target: web_view; visible: true }
            PropertyChanges { target: media; activ: true }
        },
        State {
            name: "search"
            PropertyChanges { target: search_view; visible: true }
            PropertyChanges { target: search; activ: true }
        },
        State {
            name: "chat"
            PropertyChanges { target: chat_view; visible: true }
            PropertyChanges { target: chat; activ: true }
        },
        State {
            name: "uploads"
            PropertyChanges { target: uploads_view; visible: true }
            PropertyChanges { target: uploads; activ: true }
        },
        State {
            name: "hubs"
            PropertyChanges { target: hubs_view; visible: true }
            PropertyChanges { target: hubs; activ: true }
        }
    ]
}
